var BaseHandler = function(){
    var self = this;

    self._logfunc = function(){}

    self.setLogFunc = function(logfunc){
        self._logfunc = logfunc;
    }

    self.debug = function(){
        var args = Array.prototype.slice.call(arguments);
        self._logfunc.apply(self._logfunc, args[0]);
    }

    self.info = function(){
        var args = Array.prototype.slice.call(arguments);
        self._logfunc.apply(self._logfunc, args[0]);
    }

    self.warn = function(){
        var args = Array.prototype.slice.call(arguments);
        self._logfunc.apply(self._logfunc, args[0]);
    }
    
    self.error = function(){
        var args = Array.prototype.slice.call(arguments);
        self._logfunc.apply(self._logfunc, args[0]);
    }
}

var WebHandler = function(){
    BaseHandler.apply(this);
    this.setLogFunc(cc.log);
}

var LOGLEVEL = {
    DEBUG:10,
    INFO:20,
    WARN:30,
    ERROR:40
}

var Logger = function(){
    var self = this;

    self._handlers = [];
    self._loglevel = 0;

    self.addHandler = function(handlerobj){
        self._handlers.push(handlerobj)
    }

    self.setLogLevel = function(loglv){
        self._loglevel = loglv;
    }

    self._logfac = function(logtag){
        var args;
        for (var idx in self._handlers){
            args = Array.prototype.slice.call(arguments);
            self._handlers[idx][logtag](args[1]);
        }
    }

    self.debug = function(){
        if (self._loglevel > LOGLEVEL["DEBUG"]) return;
        var args = Array.prototype.slice.call(arguments);
        self._logfac("debug", args);
    }

    self.info = function(){
        if (self._loglevel > LOGLEVEL["INFO"]) return;
        var args = Array.prototype.slice.call(arguments);
        self._logfac("info", args);
    }

    self.warn = function(){
        if (self._loglevel > LOGLEVEL["WARN"]) return;
        var args = Array.prototype.slice.call(arguments);
        self._logfac("warn", args);
    }

    self.error = function(){
        if (self._loglevel > LOGLEVEL["ERROR"]) return;
        var args = Array.prototype.slice.call(arguments);
        self._logfac("error", args);
    }
}

